class Solution {
    public void rotate(int[][] matrix) {
        if(matrix.length == 0 || matrix.length != matrix[0].length) {
            return;
        }
        //以右上-左下为对角线翻转
        int len = matrix.length;
        for(int i = 0; i < len; i++){
            for(int j = 0; j < len - i - 1; j++){
                int temp = matrix[i][j];
                matrix[i][j] = matrix[len - 1 - j][len - 1 - i];
                matrix[len - 1 - j][len - 1 - i] = temp;
            }
        }
        //以水平中线为对角线翻转
         for(int i = 0; i < (len >> 1); i++){
            for(int j = 0; j < len; j++){
                int temp = matrix[i][j];
                matrix[i][j] = matrix[len - 1 - i][j];     
                matrix[len - 1 - i][j] = temp;   
            }
        }
    }
}